package com.gsm.service.impl;

import com.gsm.entity.SysRole;
import com.gsm.dao.SysRoleDao;
import com.gsm.service.SysRoleService;
import com.gsm.entity.Result;
import com.gsm.utils.IdUtils;
import com.gsm.entity.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 系统角色表(SysRole)表服务实现类
 */
@Service
public class SysRoleServiceImpl implements SysRoleService {
    @Autowired
    private SysRoleDao sysRoleDao;
    @Autowired
    private IdUtils idUtils;

    /**
     * 新增 权限
     * @param sysRole 实例对象
     * @return
     */
    @Override
    public Result insertSysRole(SysRole sysRole) {
        long roleId = idUtils.nextId();
        sysRole.setRoleId(roleId);
        sysRoleDao.insertSysRole(sysRole);
        Result result = new Result(true,StatusCode.OK);
        return result;
    }
    
    /**
     * 根据 主键 roleId 删除
     * @param roleId 主键
     * @return
     */
    @Override
    public Result deleteSysRoleByRoleId(Long roleId) {
        sysRoleDao.deleteSysRoleByRoleId(roleId);
        Result result = new Result(true, StatusCode.OK);
        return result;
    }
    
    /**
     * 修改
     * @param sysRole 实例对象
     * @return
     */
    @Override
    public Result updateSysRoleByRoleId(SysRole sysRole) {
        sysRoleDao.updateSysRoleByRoleId(sysRole);
        Result result = new Result(true, StatusCode.OK);
        return result;
    }
    
    /**
     * 根据 id 查询单条数据
     * @param roleId 主键
     * @return
     */
    @Override
    public Result selectSysRoleByRoleId(Long roleId) {
        SysRole sysRole = sysRoleDao.selectSysRoleByRoleId(roleId);
        Result result = new Result(true, StatusCode.OK,"",sysRole);
        return result;
    }

    /**
     * 根据条件查询列表
     * @param sysRole 实例对象
     * @return
     */
    @Override
    public Result selectSysRoleList(SysRole sysRole) {
        List<SysRole> list = sysRoleDao.selectSysRoleList(sysRole);
        Result result = new Result(true, StatusCode.OK,"",list);
        return result;
    }
}